﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Logger
{
    public interface iLogger
    {
        void Log(string message);
    }

    public class LoggerFactory
    {
        public static iLogger CreateLogger()
        {
            return new FileLogger();
        }
    }

    public class FileLogger : iLogger
    {
        private string filename = @"log.txt";

        public void Log(string message)
        {
            if (!File.Exists(filename))
            {
                using (StreamWriter sw = File.CreateText(filename))
                {
                    sw.WriteLine("[{0} {1}] Создан файл.", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());
                    sw.WriteLine("[{0} {1}] {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), message); ;
                }
            }
            else
            {
                using (StreamWriter sw = File.AppendText(filename))
                {
                    sw.WriteLine("[{0} {1}] {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), message);
                }
            }
        }
    }
}
